package com.heima.wemedia.controller;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.heima.common.dto.PageResponseResult;
import com.heima.common.dto.ResponseResult;
import com.heima.wemedia.dto.NewsAuthDto;
import com.heima.wemedia.dto.WmNewsDto;
import com.heima.wemedia.dto.WmNewsPageDto;
import com.heima.wemedia.entity.WmNews;
import com.heima.wemedia.vo.WmNewsVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.heima.wemedia.service.IWmNewsService;
import java.util.List;
import java.util.Map;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 自媒体图文内容信息表 前端控制器
 * </p>
 *
 * @author mcm
 * @since 2021-05-22
 */
@RestController
@RequestMapping("/api/v1/news")
@Api(tags = "自媒体图文内容信息表接口")
@CrossOrigin
public class WmNewsController{

    @Autowired
    private IWmNewsService wmNewsService;

    @PostMapping("/list")
    @ApiOperation(value = "自媒体文章列表", notes = "author:mcm")
    public ResponseResult findListByCondition(@RequestBody WmNewsPageDto dto){
        return wmNewsService.findListByCondition(dto);
    }

    @PostMapping("/submit")
    @ApiOperation(value = "发布，修改，保存草稿", notes = "author:mcm")
    public ResponseResult submit(@RequestBody WmNewsDto dto){
        return wmNewsService.submit(dto);
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "查看文章", notes = "author:mcm")
    public ResponseResult<WmNews> getById(@PathVariable Integer id){
        WmNews wmNews = wmNewsService.getById(id);
        return ResponseResult.okResult(wmNews);
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除文章", notes = "author:mcm")
    public ResponseResult deleteNews(@PathVariable Integer id){
        return wmNewsService.deleteNews(id);
    }

    @PutMapping("/down_or_up")
    @ApiOperation(value = "上下架文章", notes = "author:mcm")
    public ResponseResult upOrDown(@RequestBody WmNewsDto dto){
        return wmNewsService.upOrDown(dto);
    }

    @PutMapping
    @ApiOperation(value = "修改文章", notes = "author:mcm")
    public ResponseResult updateById(@RequestBody WmNews wmNews){
        wmNewsService.updateById(wmNews);
        return ResponseResult.okResult();
    }

    @GetMapping("/getRelease")
    @ApiOperation(value = "查询待发布文章状态", notes = "author:mcm")
    public ResponseResult<List<Integer>> getRelease(){
return wmNewsService.getRelease();
    }

    @PostMapping("/findPageByName")
    @ApiOperation(value = "查询人工审核文章列表", notes = "author:mcm")
    public PageResponseResult  findPageByName(@RequestBody NewsAuthDto dto){
        return wmNewsService.findPageByName(dto);
    }

    @GetMapping("/findNewsVoById/{id}")
    @ApiOperation(value = "查询审核文章", notes = "author:mcm")
    public ResponseResult<WmNewsVo> findNewsVoById(@PathVariable("id") Integer id){
        return wmNewsService.findNewsVoById(id);
    }
}
